package org.hcyspartnoc.luoxin.common.core.context;


public class BaseContextHolder {

    // 创建一个线程变量，类型为BaseContext
    private static final ThreadLocal<BaseContext> contextHolder = new ThreadLocal<>();

    public BaseContextHolder() {
    }

    // 设置变量
    public static void setContext(BaseContext baseContext) {
        contextHolder.set(baseContext);
    }

    public static BaseContext getContext() {
        BaseContext obj = contextHolder.get();
        if (obj == null) {
            // 如果为空就创建一个新的
            obj = new BaseContextImpl();
            setContext((BaseContext) obj);
        }
        return (BaseContext) obj;
    }

}

